<template>
  <div class="layout-pd">
    <zh-space>
      <zh-card>
        <zh-form ref="queryForm" :model="state.queryParam">
          <zh-form-select
              prop="processKey"
              label="流程业务名称"
              placeholder="单选"
              :options="state.dictData.PROCESSKEY"
              v-model="state.queryParam.processKey"
          ></zh-form-select>
          <zh-col>
            <zh-button buttonType="query" @click="findList">
              查询
            </zh-button>
          </zh-col>
        </zh-form>
      </zh-card>
      <el-row style="width: 100%" class="flow-manage">
        <el-card style="width: 100%">
          <template #header>
            <div class="card-header">
              <span>流程业务模块</span>
            </div>
          </template>
          <div>
            <el-row style="width: 100%;height: calc(100vh - 360px);overflow-y: auto">
              <el-col :span="6" v-for="(item,index) in state.processList" :key="index" style="padding-left: 8px;padding-right: 8px;padding-bottom: 16px;">
                <div class="card-in" @click="openDesign(item)">
                  <div class="flow-icon">
                    <img src="
                  GdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAeUExURf///zKW+ur0/nO4+6XR/YvE/Eqi+5DG/Nnr/sPg
                  /brnfYAAAAFMSURBVFjD7dfPSsNAEAbwNTGtuXVM09pbqCAeFV8gwYNXtU+wioI3FcFrLorH+OeBncYuSnYl
                  +wUKEueDNmHhR8rO7myqqGOUQIECBQoUaDK5dsQD3ihXNtth6YTqtQ0mbqcGbXD8C4z6BYPFUSP3ftCawOVU+8ANe
                  zH5QXuVzDwnJ5g38nfruP/SSOYHh9bkjNdcjrDrAghOHhvJe7ettlab6RaFA9fDkTpOURivbi963OX+H/x4qLrA4I
                  zHzjvA57pzVDCMsU7+nT0eKfiTofCQKF2SAxAGPLBdf4GQz63LXB1rHsVgRDtfD05BGLKofQJDOuXLHQyHdQm5mOhP
                  jQ2coXXUXIiM6zFCYUGj3aTUlKMwpIQPOd9j7ufS0abDotsqMu+wcAd40nRV+sCp1W0ysxbW9GpNlRsWrTB9mzvyLn
                  /KBAoUKFCgyScZMYmWkzKSDQAAAABJRU5ErkJggg==" width="60">
                  </div>
                  <div class="ant-space ant-space-vertical" style="gap: 8px;">
                    <div class="ant-space-item" style="">
                      <div class="first-edit"><strong><span>{{ item.processName }}</span><!----></strong><!----></div>
                    </div>
                    <div class="ant-space-item" style="">
                      <!--                    <div>2022-11-27 01:04:49</div>-->
                    </div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-row>

      <zh-dialog
          :title="state.modalTitle"
          width="50%"
          v-model="state.visible"
          @confirm="handleCustomData"
      >
        <flow-long ref="flowLongPage" :processData="state.selectProcessData" :showAddButton="false"/>
      </zh-dialog>

    </zh-space>


  </div>
</template>

<script lang="ts" setup name="flowActorConfig">
import {nextTick, onMounted, reactive, watch,ref} from "vue";
import FlowLong from "@/views/system/workflow/flowLong/component/flowLong.vue";
import jsonBig from 'json-bigint'


const flowLongPage = ref();
const actorConfigFormPage = ref();
const state = reactive({
  advanced: false,
  dictData: {
    PROCESSKEY: [],
  },
  queryParam: {
    processKey: undefined
  },
  tableColumn: [
    { type: "seq", width: 80, fixed: "left", align: "center", title: "序号" },
    { field: "orgName", title: "组织名称", align: "center", fixed: "left", width: 200 },
    { field: "processName", title: "流程业务名称", align: "center", fixed: "left", width: 180 },
    { field: "nodeName",title: "节点名称",align: "center",fixed: "left",width: 200,},
    { field: "fullNameList", title: "人员", align: "center", width: 220 },
    { field: 'operate', title: '操作', align: 'center', fixed: 'right', width: 280, slots: { default: 'operate_default' } },
  ],
  campusParam: {},
  visible: false,
  selectRow: {},
  processList: [],
  modalTitle: '',
  selectProcessData: undefined,
  selectProcessKey: undefined,
  selectProcessName: undefined,
})

function initDict() {
  $api.common.send
      .post("flowLongDeploy017", {})
      .then((res) => {
        state.processList = res.result;
        const PROCESSKEY = [];
        if(res.result && res.result.length > 0){
          res.result.forEach(e=>{
            let item = {};
            item.dictKey = e.processKey;
            item.dictValue = e.processName;
            PROCESSKEY.push(item);
          })
        }
        state.dictData.PROCESSKEY = PROCESSKEY;
      })
      .catch(() => {});
}

function findList() {
  $api.common.send
      .post("flowLongDeploy017", {processKey: state.queryParam.processKey})
      .then((res) => {
        state.processList = res.result;
      })
      .catch(() => {});
}

function openDesign(row) {
  state.selectProcessData = jsonBig.parse(row.modelContent);
  state.modalTitle = "流程配置";
  state.visible = true;
}

function handleCustomData() {
  const customData = flowLongPage.value.getCustomData();
  //走接口插入数据
  if(customData && customData.length > 0){
    const params = [];
    customData.forEach(item => {
      const paramItem = {};
      paramItem.id = item.flwTaskActorConfigId;
      paramItem.configType = item.config001;
      paramItem.processKey = state.selectProcessKey;
      paramItem.processName = state.selectProcessName;
      paramItem.nodeId = item.nodeId;
      paramItem.nodeName = item.nodeName;
      paramItem.nodeUserList = item.nodeUserList;
      paramItem.examineMode = item.examineMode;
      paramItem.nodeType = item.type;
      params.push(paramItem);
    })
    $api.common.send
        .post("flowLongDeploy018", {flwTaskActorConfigVOList: params})
        .then((res) => {
          $messageBox.success("配置成功", "提示");
          findList();
          cancel();
        })
        .catch(() => {});
  }
}

function cancel() {
  state.visible = false;
}


onMounted(() => {
  nextTick(() => {
    initDict();
  });
});
</script>

<style scoped lang="less">
.work-bench-layout {
  padding: 10px;
  width: 100%;
}

.app-todo {
  cursor: pointer;
  border-radius: 4px;
  box-shadow: none; /* 初始化为无阴影 */
  transition: box-shadow 0.3s ease; /* 平滑过渡阴影变化 */

  &:hover {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); /* 鼠标悬浮时显示阴影 */
  }

  .mt-icon {
    text-align: center;
    line-height: 80px;
    font-size: 42px;
  }

  .mt-title {
    font-size: 18px;
    padding: 10px 0 0;
  }

  .mt-value {
    font-size: 32px;
    font-weight: 700;
  }
}

.app-task {
  cursor: pointer;
  border-radius: 10px;
  text-align: center;
  padding: 0 0 10px;

  &:hover {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); /* 鼠标悬浮时显示阴影 */
  }

  .app-task-icon {
    font-size: 32px;
    margin-bottom: 4px;
  }

  .app-task-title {
    font-size: 16px;
  }
}

.flow-manage {
  .card-header {
    font-size: 16px;
    padding-left: 10px;
  }
  .card-in {
    height: 100px;
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: row;
    width: 100%;
    border: 1px solid #d9d9d9;
    background: var(--component-background);
    cursor: pointer;
    transition: border-color 0.3s; /* 平滑过渡边框颜色 */
    >div:nth-child(1) {
      flex: 0 0 66px;
    }
    img {
      height: 100%;
    }
    &:hover {
      border-color: #2e2ee2; /* 鼠标悬浮时的边框颜色 */
    }
  }

}
:deep(.el-dialog__body) {
  overflow-x: auto !important;
}
</style>